package cn.snowheart.mapper;

import cn.snowheart.pojo.Person;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author liuwanxiang
 * @version 2018/4/21
 */
public interface PersonMapper {

    /**
     * 插入Person记录
     *
     * @param person
     * @return
     */
    @Insert("INSERT INTO PERSONS(NAME,AGE) VALUES(#{name},#{age})")
    int insertPerson(Person person);

    /**
     * 删除Person记录
     *
     * @param id
     * @return
     */
    @Delete("DELETE FROM PERSONS WHERE ID = #{id}")
    int deletePerson(Integer id);

    /**
     * 通过主键查询Person
     *
     * @param id
     * @return
     */
    @Select("SELECT * FROM PERSONS WHERE ID = #{id}")
    Person getPerson(Integer id);

    /**
     * 查询所有的Person
     *
     * @return
     */
    @Select("SELECT * FROM PERSONS")
    List<Person> getPersons();

    /**
     * 更新
     *
     * @param person
     * @return
     */
    @Update("UPDATE PERSONS SET NAME = #{name}, AGE = #{age} WHERE ID = #{id}")
    int updatePerson(Person person);

}